﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;

namespace HRM.UI.PmUI.Profile
{
    public partial class ApplicationStatus : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadReamainingLeave();
                GetApplicationStatus();
            }
        }
        private void LoadReamainingLeave()
        {
            //welcomeMsgLbl.Text = Session["name"].ToString();

            LeaveStatus leaveStatus = new LeaveStatus();
            LeaveStatusManager leaveStatusManager = new LeaveStatusManager();
            Code code = new Code();
            code.CodeName = (string)Session["Code"];
            leaveStatus = leaveStatusManager.GetEmployeeLeaveStatus(code);
            earnLeaveLbl.Text = leaveStatus.EarnLeave.ToString();
            casualLeaveLbl.Text = leaveStatus.CasualLeave.ToString();
            sickLeaveLbl.Text = leaveStatus.SickLeave.ToString();
            otherLbl.Text = leaveStatus.Others.ToString();
        }
        private void GetApplicationStatus()
        {
            Code code = new Code();
            code.CodeName = Session["Code"].ToString();
            ApplicationManager manager = new ApplicationManager();
            List<LeaveApplication> leaveApplications = new List<LeaveApplication>();
            leaveApplications = manager.GetApplicationStatus(code);
            applicationStatusGdv.DataSource = leaveApplications;
            applicationStatusGdv.DataBind();
        }

        protected void applicationStatusGdv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            foreach (GridViewRow gvr in applicationStatusGdv.Rows)
            {
                Label label = (Label)gvr.FindControl("Label1");
                if (label.Text == "Pending")
                {
                    label.ForeColor = Color.FromArgb(255, 211, 134, 136);
                }
                if (label.Text == "Rejected")
                {
                    label.ForeColor = Color.Red;
                }
                if (label.Text == "Approved")
                {
                    label.ForeColor = Color.Green;
                }
                label.Font.Bold = true;
            }
        }
    }
}